<template>
  <el-dialog
    title="助教打卡"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="助教老师" prop="zjTeacherId">
        <el-select v-model="dataForm.zjTeacherId" filterable placeholder="老师姓名">
            <el-option
              v-for="item in teacherList"
              :key="item.id"
              :label="item.teacherName"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          zjTeacherId: ''
        },
        teacherList: [],
        dataRule: {
          zjTeacherId: [
            { required: true, message: '助教老师不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id
        this.dataForm.zjTeacherId = ''
        this.visible = true
        this.teacherList = []
        this.getTeacherList()
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/business/sign/zjSign`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id,
                'zjTeacherId': this.dataForm.zjTeacherId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      // 获取助教老师
      getTeacherList () {
        this.$http({
          url: this.$http.adornUrl('/business/teacher/getTeacherList'),
          mothod: 'get',
          params: {

          }
        }).then(({data}) => {
          if (data.code === 0) {
            this.teacherList = data.list
          }
        })
      }
    }
  }
</script>
